package Service;

import Utils.PacketUtils;
import org.json.JSONObject;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * The type Register.
 *
 * @author dzr
 * @version 1.0
 */
public class Register {
    /**
     * The constant REGISTER.
     */
    public static final int REGISTER = 0;

    /**
     * Register.
     *
     * @param name     the name
     * @param pwd      the pwd
     * @param birthday the birthday
     * @param sex      the sex
     * @return the int
     * @throws IOException the io exception
     */
    public static int register(String name, String pwd, String birthday, String sex) throws IOException {
        JSONObject ret2Server = new JSONObject();
        ret2Server.put("cmd", REGISTER);
        ret2Server.put("username", name);
        ret2Server.put("pwd", pwd);
        ret2Server.put("birthday", birthday);
        ret2Server.put("sex", sex);

        PacketUtils.sendPacket(ret2Server);
        JSONObject msg = PacketUtils.receivePacket();
        return msg.getInt("uid");
    }
}
